﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using YSC_Core.BLL.Domain.BackstageModels;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_Backstage_Web.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    public class RoleController : Controller
    {
        private IUserBackstageServices _rep;

        public RoleController(IUserBackstageServices rep)
        {
            this._rep = rep;
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public IActionResult List()
        {
            return View();
        }

        /// <summary>
        /// 角色新增
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 角色修改
        /// </summary>
        /// <returns></returns>
        public IActionResult Edit()
        {
            return View();
        }


        /// <summary>
        /// 菜单授权
        /// </summary>
        /// <returns></returns>
        public IActionResult MeunEdit(string id)
        {
            ViewData["Id"] = id;
            return View();
        }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="sasearch"></param>
        /// <returns></returns>
        public JsonResult GetRoleAll(int index, int size, string sasearch)
        {
            var ret = _rep.GetRoleAll(index, size, sasearch);
            return Json(ret);
        }

        /// <summary>
        /// 角色所属菜单
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public JsonResult GetRoleMenu(string roleid)
        {
            var ret = _rep.GetRoleMenu(roleid);
            return Json(ret);
        }


        public JsonResult AddUpdateRoleMenu(string paramete)
        {
            UpdateRoleMenu entity = JsonConvert.DeserializeObject<UpdateRoleMenu>(paramete);
            var ret = _rep.AddUpdateRoleMenu(entity);
            return Json(ret);
        }

    }
}